package com.leecreate.tutool.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory;

@Configuration
public class MultipleMongoConfig {
    @Value("${spring.data.mongodb.uri}")
    private String primaryUri;

    @Primary
    @Bean(name = "MongoTemplate")
    public MongoTemplate mongoTemplate() throws Exception {
        SimpleMongoClientDbFactory simpleMongoClientDbFactory = new SimpleMongoClientDbFactory(primaryUri);
        return new MongoTemplate(simpleMongoClientDbFactory);
    }

}
